package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品功能模块")
public class DishController {

    @Autowired
    DishService dishService;

    @PutMapping
    public Result updateDish(@RequestBody DishDTO dto){
         dishService.updateDish(dto);
        return Result.success();
    }


    @PostMapping("status/{status}")
    public Result update(@PathVariable("status") Integer status,@RequestParam("id") Long id){
        dishService.update(status,id);
        return Result.success();
    }

    @GetMapping("{id}")
    public Result getById(@PathVariable Long id){
      DishVO dish=  dishService.getById(id);
      return Result.success(dish);
    }


    @DeleteMapping
    public Result delIds(@RequestParam List<Long> ids){
        dishService.delete(ids);
        return Result.success();
    }


    /**
     * 菜品的分页查询
     * @param dto
     * @return
     */
    @GetMapping("page")
    public Result getPage(DishPageQueryDTO dto){
      PageResult result = dishService.getPage(dto);
        return Result.success(result);
    }

    /**
     * 添加菜品
     * @param dto
     * @return
     */
    @PostMapping
    public Result save(@RequestBody DishDTO dto){
        dishService.save(dto);
        return Result.success();
    }

    @GetMapping("/list")
    public Result getListById(@RequestParam Long categoryId ){
       List<Dish> result = dishService.getListById(categoryId);
        return Result.success(result);
    }
}
